/**
 * 
 */
package flinty.autocomplete.combobox;

public final class ItemWrapper<T> {
	private final T object;

	private String caption;

	public ItemWrapper(T obj, String cap) {
		object = obj;
		caption = cap;
		if (caption == null) {
			caption = "";
		}
	}

	T getObject() {
		return object;
	}

	@Override
	public String toString() {
		return caption;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ItemWrapper<?>) {
			ItemWrapper<?> iw2 = (ItemWrapper<?>) obj;
			if (object == null) {
				return iw2.object == null && caption.equals(iw2.caption);
			}
			return object.equals(iw2.object) && caption.equals(iw2.caption);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return (object == null ? 0 : object.hashCode()) & caption.hashCode();
	}
}